using UnityEngine;

public class RocketLeagueBall : MonoBehaviour
{
	public Rigidbody ballRigidbody;

	public PhotonView ballPhotonView;

	public RocketLeagueBallPhoton rocketLeagueBallPhoton;

	public float collisionForce = 1f;

	public float ballPos = 2f;

	private void OnTriggerEnter(Collider other)
	{
		if (ballPhotonView.isMine)
		{
			if (other.tag == "RocketLeagueGateBlue")
			{
				RocketLeagueCotroller.instance.Goal(PunTeams.Team.red, PlayerBehavior.MyPlayer.ID, PlayerBehavior.MyPlayer.Nick);
			}
			else if (other.tag == "RocketLeagueGateRed")
			{
				RocketLeagueCotroller.instance.Goal(PunTeams.Team.blue, PlayerBehavior.MyPlayer.ID, PlayerBehavior.MyPlayer.Nick);
			}
		}
	}

	private void OnTriggerExit(Collider other)
	{
		if (ballPhotonView.isMine)
		{
			if (other.tag == "RocketLeagueGateBlueSave")
			{
				RocketLeagueCotroller.instance.GoalSave(PunTeams.Team.blue);
			}
			else if (other.tag == "RocketLeagueGateRedSave")
			{
				RocketLeagueCotroller.instance.GoalSave(PunTeams.Team.red);
			}
		}
	}

	public void ApplyCarCollisionForce(float carSpeed, Vector3 carPosition, Collision collision)
	{
		Vector3 vector = base.transform.position - Vector3.up * ballPos;
		ballRigidbody.AddForceAtPosition((vector - carPosition).normalized * collisionForce * carSpeed, collision.contacts[0].point, ForceMode.Impulse);
	}
}
